package cn.com.aisat.android.videoshow;

import cn.com.aisat.android.videoshow.data.MovieItem;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

public class MovieShowActivity extends Activity {
	private int sScreenWidth = 1280; // 屏幕的宽和高。
	private int sScreenHeight = 720;
	private TextView tv_name = null, tv_director = null, tv_starring = null,
			tv_category = null;
	private TextView tv_language = null, tv_length = null,
			tv_content_desc = null;
	private TextView tv_picture, tv_origin, tv_capcity, tv_quantity;
	private Button tv_play = null, tv_favorite = null, tv_download = null,
			tv_more = null;
	/**
	 * 电影图片
	 */
	private ImageView tv_image_cover = null;

	private ImageView star1 = null, star2 = null, star3 = null, star4 = null,
			star5 = null;
	private MovieItem item = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		WindowManager wm = (WindowManager) this
				.getSystemService(Context.WINDOW_SERVICE);
		sScreenWidth = wm.getDefaultDisplay().getWidth();
		sScreenHeight = wm.getDefaultDisplay().getHeight();

		setContentView(R.layout.movie_show);

		tv_image_cover = (ImageView) findViewById(R.id.tv_show_img_cover);

		tv_name = (TextView) findViewById(R.id.tv_show_tv_name);
		tv_director = (TextView) findViewById(R.id.tv_show_tv_director);
		tv_starring = (TextView) findViewById(R.id.tv_show_tv_starring);

		tv_category = (TextView) findViewById(R.id.tv_show_tv_category);
		tv_language = (TextView) findViewById(R.id.tv_show_tv_language);
		tv_length = (TextView) findViewById(R.id.tv_show_tv_length);

		tv_picture = (TextView) findViewById(R.id.tv_show_tv_picture);
		tv_origin = (TextView) findViewById(R.id.tv_show_tv_origin);
		tv_capcity = (TextView) findViewById(R.id.tv_show_tv_capcity);
		tv_quantity = (TextView) findViewById(R.id.tv_show_tv_quantity);

		star1 = (ImageView) findViewById(R.id.tv_show_img_stars1);
		star2 = (ImageView) findViewById(R.id.tv_show_img_stars2);
		star3 = (ImageView) findViewById(R.id.tv_show_img_stars3);
		star4 = (ImageView) findViewById(R.id.tv_show_img_stars4);
		star5 = (ImageView) findViewById(R.id.tv_show_img_stars5);

		tv_content_desc = (TextView) findViewById(R.id.tv_show_tv_content_desc);

		tv_play = (Button) findViewById(R.id.tv_show_btn_paly);
		tv_favorite = (Button) findViewById(R.id.tv_show_btn_favorite);
		tv_download = (Button) findViewById(R.id.tv_show_btn_download);
		tv_more = (Button) findViewById(R.id.tv_show_btn_more);

		tv_play.setOnClickListener(onClickListener);
		tv_favorite.setOnClickListener(onClickListener);
		tv_download.setOnClickListener(onClickListener);
		tv_more.setOnClickListener(onClickListener);
		item = (MovieItem) getIntent().getSerializableExtra("item");

		initData(item);

	}

	final OnClickListener onClickListener = new OnClickListener() {

		public void onClick(View view) {
			switch (view.getId()) {
			case R.id.tv_show_btn_paly:

				break;

			case R.id.tv_show_btn_favorite:

				break;
			case R.id.tv_show_btn_download:

				break;

			default:
				break;
			}
		}
	};

	private void initData(MovieItem tvshow) {
		if (tvshow != null) {
			tv_name.setText(tvshow.getName() == null ? "" : tvshow.getName());
			tv_director.setText(tvshow.getTv_show_tv_director() == null ? ""
					: tvshow.getTv_show_tv_director());
			tv_starring.setText(tvshow.getTv_show_tv_starring() == null ? ""
					: tvshow.getTv_show_tv_starring());

			tv_category.setText(tvshow.getTv_show_tv_category() == null ? ""
					: tvshow.getTv_show_tv_category());
			tv_language.setText(tvshow.getTv_show_tv_language() == null ? ""
					: tvshow.getTv_show_tv_language());
			tv_length.setText(tvshow.getTv_show_tv_length() == null ? ""
					: tvshow.getTv_show_tv_length());

			tv_picture.setText(tvshow.getTv_show_tv_picture() == null ? "   "
					: tvshow.getTv_show_tv_picture());
			tv_origin.setText(tvshow.getTv_show_tv_origin() == null ? "   "
					: tvshow.getTv_show_tv_origin());
			tv_capcity.setText(tvshow.getTv_show_tv_capcity() == null ? "   "
					: tvshow.getTv_show_tv_capcity());
			tv_quantity.setText(tvshow.getTv_show_tv_quantity() == null ? "   "
					: tvshow.getTv_show_tv_quantity());
			show_Stars(tvshow.getStars() == null ? "   " : tvshow.getStars());

			tv_content_desc
					.setText(tvshow.getTv_show_tv_content_desc() == null ? ""
							: tvshow.getTv_show_tv_content_desc());

		}
	}

	/**
	 * 将字符串(本质为数字1-5)的数字转换成星星图标显示
	 * 
	 * @param string
	 */
	private void show_Stars(String string) {
		int stars = 0;
		try {
			stars = Integer.parseInt(string);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		if (stars >= 5) {
			return;
		}
		if (stars == 4) {
			star5.setVisibility(View.INVISIBLE);
		}
		if (stars == 3) {
			star5.setVisibility(View.INVISIBLE);
			star4.setVisibility(View.INVISIBLE);
		}
		if (stars == 2) {
			star5.setVisibility(View.INVISIBLE);
			star4.setVisibility(View.INVISIBLE);
			star3.setVisibility(View.INVISIBLE);
		}
		if (stars == 1) {
			star5.setVisibility(View.INVISIBLE);
			star4.setVisibility(View.INVISIBLE);
			star3.setVisibility(View.INVISIBLE);
			star2.setVisibility(View.INVISIBLE);
		}
		if (stars < 1) {
			star5.setVisibility(View.INVISIBLE);
			star4.setVisibility(View.INVISIBLE);
			star3.setVisibility(View.INVISIBLE);
			star2.setVisibility(View.INVISIBLE);
			star1.setVisibility(View.INVISIBLE);
		}
	}

}